//
//  photoViewController.m
//  timemovie
//
//  Created by Yiqiao on 15/7/23.
//  Copyright (c) 2015年 Yiqiao. All rights reserved.
//

#import "photoViewController.h"
#import "photoCollection.h"
#define w [UIScreen mainScreen].bounds.size.width
#define h [UIScreen mainScreen].bounds.size.height
#define navH 64;
#define barH 49;
@interface photoViewController ()

@end

@implementation photoViewController

- (void)_createNav{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"back" style:UIBarButtonItemStyleDone target:self action: @selector(cancelAct)];
}

- (void)_createCollection{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = self.view.bounds.size;
    layout.minimumLineSpacing  = 30;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
   
    _collectionView = [[photoCollection alloc]initWithFrame:CGRectMake(0, 0, w+30, h) collectionViewLayout:layout];
   
    _collectionView.imageUrlArray = self.imageUrlArray;
    NSIndexPath *path = [NSIndexPath indexPathForItem:self.currentTag inSection:0];
    [_collectionView scrollToItemAtIndexPath:path atScrollPosition:UICollectionViewScrollPositionLeft  animated:YES];
   
    [_collectionView reloadData];
    [self.view addSubview:_collectionView];
}

- (void)setImageUrlArray:(NSMutableArray *)imageUrlArray{
    _imageUrlArray = imageUrlArray;
   // _collectionView.imageUrlArray = _imageUrlArray;
    
}

- (void)cancelAct{
    [self dismissViewControllerAnimated:YES completion:nil];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self _createNav];
    
    [self _createCollection];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hiddenNav) name:@"hidden" object:nil];
    
    // Do any additional setup after loading the view.
}

- (void)hiddenNav{
    BOOL isHidden = self.navigationController.navigationBar.isHidden;
    [self.navigationController setNavigationBarHidden:!isHidden animated:YES];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
